1 Introduction

The role of the independent sector in the provision of elective care has been brought into the spotlight by rising pressures of the NHS and growing waiting lists. Our analysis aims to contribute to existing work undertaken by the Health Foundation investigating the landscape of independent sector healthcare services.

The Health Foundation found an increasing proportion of care is delivered by the independent sector; this varies by specialitiy and is highest in T&O, GI and ophthalmology. Treatment rates in all specialities are not achieving the 30%-increase target set to address the backlog of care. The Health Foundation suggests uptake in the independent sector is matching the reductions in NHS provided care. It was also found that the independent sector share of provision varies regionally and by deprivation measures.

We aim to further the above analysis by utilising patient-level inpatient and outpatient data to more closely examine trends in independent sector care. Given the above findings, we will focus on ophthalmology and orthopaedic care, presenting our findings by demographics, geographically and by procedure.


2 Methods

In an exploratory fashion, we will present the changing market share of independent care in elective ophthalmic and orthopaedic services. We will be guided by our preliminary findings starting by assessing patterns in national data developing on to consider local findings.

2.1 Data collection


We gathered acute inpatient and outpatient data via the Secondary Uses Services (SUS) dataset, accessed through the National Commissioning Data Repository (NCDR) platform. To capture the pre-pandemic context, we limit our data to the years 2017 through to 2022. We count completed inpatient admissions or outpatient attendances filtered to only include non-emergency contacts with selected Healthcare Resource Group (HRG) codes.

The HRG code describes the content of an admission in terms of resource required and is linked to the of commissioning care. We use commissioning codes rather than procedure codes because data completeness is preferable and they offer the suitable level of granularity for data processing and presentation of findings. All HRG codes were updated to their corresponding code in the most recent HRG version. The activity we captured was linked to the following HRG codes (right).

Data was accessed at a national level with local feilds included to indicate the patient’s ICS and local authority of residence. Similarly, the low level geography (LSOA) of the patient was included to link to the Index of Multiple Deprivation (IMD) to assign each admission to a deprivation decile (1 = most deprived 10% of the population, 10 = the most affluent 10% of the population).

The SUS data contains only NHS-funded care. We identified the sector in which the care was delivered by assessing the ODS provider type, linked to site (hospital/care centre) in which the care occurred. We compare the rate of NHS-funded care delivered in NHS sites to NHS-funded care delivered in independent sector sites. Limitations of our data dictate that we do not count any privately funded care, regardless of site of delivered.


Subchapter BZ – Eyes and Periorbita Procedures and Disorders:

create_dt(
  hrg_lookup %>% 
  filter(str_detect(procedure_group, "Eyes")) %>% 
  select(1,2) %>% 
  rename(HRG = hrg_3, 
         Procedure = procedure_desc)
  )

Subchapter HN – Orthopaedic Non-Trauma Procedures:

create_dt(
  hrg_lookup %>% 
  filter(str_detect(procedure_group, "Orthopaedic")) %>% 
  select(1,2) %>% 
  rename(HRG = hrg_3, 
         Procedure = procedure_desc)
  )

2.2 Data processing

Activity data was grouped by demographic, geographic and activity-type variables and counts of episodes, spells (admissions or attendances) and individuals were calculated. Aggregated data was exported from the NCDR SQL server and processed locally in RStudio/RMarkdown.

For each group of interest we had activity counts for care delivered in both the independent sector (IS) and in NHS clinical settings. We calculated the independent sector market share (%) as follows:

\[ IndependentSectorShare = ISActivity / (ISActivity + NHSActivity) * 100 \]

Incomplete admissions/attendances, i.e. those without a discharge date, were excluded. Similarly, those without valid identification numbers were excluded.

Upon publication of our findings, the underlying code will be available on Github.


3 Results

3.1.2 Inc. costs

3.1.2.1 Orthopadeic

# Orthopaedic
national_data %>% 
  group_by(der_activity_month, type, speciality) %>% 
  sum_spells_function(.) %>%  
  pivot_longer(cols = c(-der_activity_month, -type, -speciality)) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", 
                          str_detect(name, "OP") ~ "Outpatient appointments",
                          TRUE ~ "Cost (£)")) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>% 
  filter(speciality == "Orthopaedic") %>% 
  
  ggplot(aes(x = der_activity_month, y = value, colour = name, group = name)) +
  geom_point(alpha = 0.4) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_grid(str_wrap(name,15) ~ type, scales = "free") +
  scale_color_SU() +
  scale_y_continuous(labels = comma, oob = squish) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "none"
        ) +
  labs(x = "", y = "", colour = "Activity",
       title = "Trends in activity and cost by speciality and sector: Orthopaedic",
       subtitle = "Monthly elective activity | National | 2018-22")

3.1.2.2 Ophthalmology

# Ophthalmology
national_data %>% 
  group_by(der_activity_month, type, speciality) %>% 
  sum_spells_function(.) %>% 
  pivot_longer(cols = c(-der_activity_month, -type, -speciality)) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", 
                          str_detect(name, "OP") ~ "Outpatient appointments",
                          TRUE ~ "Cost (£)")) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>% 
  filter(speciality == "Ophthalmology") %>% 
  
  ggplot(aes(x = der_activity_month, y = value, colour = name, group = name)) +
  geom_point(alpha = 0.4) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_grid(str_wrap(name,15) ~ type, scales = "free") +
  scale_color_SU() +
  scale_y_continuous(labels = comma, oob = squish) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "none"
        ) +
  labs(x = "", y = "", colour = "Activity",
       title = "Trends in activity and cost by speciality and sector: Ophthalmology",
       subtitle = "Monthly elective activity | National | 2018-22")

The predominant type of ophthalmic care varies by sector; in NHS settings, more than 2 in every 3 contacts are delivered via outpatient attendances, where as care in the independent sector is most often provided in the form of inpatients admissions. These differences are likely a function of the types of procedures considered suitable to outsource from the NHS to independent providers.

3.1.3 Independent sector share

national_data %>%
  group_by(der_activity_month, type, speciality) %>% 
  sum_spells_function(.) %>% 
  group_by(der_activity_month, type, speciality) %>% 
  mutate(total_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  pivot_longer(cols = c(-der_activity_month, -type, -speciality)) %>% 
  pivot_wider(id_cols = c(der_activity_month, speciality, name), 
              names_from = type,
              values_from = value
              ) %>% 
  group_by(der_activity_month, speciality, name) %>% 
  mutate(prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient", 
                          str_detect(name, "OP") ~ "Outpatient",
                          str_detect(name, "cost") ~ "Cost",
                          TRUE ~ "All activity")) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  filter(name %in% c("Inpatient", "Outpatient")) %>% 
  
  ggplot(aes(x = der_activity_month, y = prop, colour = name, group = name)) +
  geom_point(alpha = 0.4) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~speciality#, scales = "free_y"
             ) +
  scale_color_SU() +
  scale_y_continuous(labels = comma, oob = squish) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "bottom"
        ) +
  labs(x = "", y = "Independent sector market share (%)", colour = "Activity type", 
       title = "Share of activity delivered by the independent sector",
       subtitle = "Monthly elective inpatient and outpatient activity | National | 2017-22")

In considering the changing independent sector market share in both ophthalmic and orthopaedic care, we can see that inpatient activity is the dominate care type. In ophthalmic care, the proportion of care delievered by the IS has grown at a steadily increasing rate through our data collection period, excluding the COVID-19; this is in contrast to the outpatient ratio, which has grown at a lesser rate.

Is it the case that the increase in the proportion of care delivered by the IS through inpatient activity is driven by cataract surgeries and the growth in the outpatient trend is a result of the increasing share of Vitreous Retinal procedures?

The independent sector’s market share of orthopaedic care is larger and more consistent than in ophthalmic procedures. The growth in independent sector provision is less pronounced in orthopaedic care. A large spike in inpatient independent sector activity was seen during the immediate COVID-19 pandemic recovery. Independent sector provision proportion then returned to closer to pre-pandemic levels and has been steadily growing since mid-2021.

In the above chart, the yellow ‘All activity’ line is the sum of the two care type proportions (inpatient % + outpatient % = all activity %).

3.1.4 Orthopaedic procedures

3.1.4.1 Volume

3.1.4.1.1 Fixed scale
national_data_procedure %>%  
  filter(speciality == "Orthopaedic") %>% 
  group_by(der_activity_month, type, speciality, procedure_desc_short) %>% 
  mutate(all_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  
  ggplot(aes(x = der_activity_month, y = all_activity, colour = type)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short#, scales = "free"
             ) +
  scale_color_SU() +
  scale_y_continuous(labels = comma) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "bottom"
        ) +
  labs(x = "", y = "Activity", colour = "Sector",
       title = "Trends in Orthopaedic activity by sector and procedure",
       subtitle = "Monthly elective inpatient admissions and outpatient appointments | National | 2017-22")

Chart text …

3.1.4.1.2 Free scale
national_data_procedure %>%  
  filter(speciality == "Orthopaedic") %>% 
  group_by(der_activity_month, type, speciality, procedure_desc_short) %>% 
  mutate(all_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  
  ggplot(aes(x = der_activity_month, y = all_activity, colour = type)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short, scales = "free") +
  scale_color_SU() +
  scale_y_continuous(labels = comma) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "bottom"
        ) +
  labs(x = "", y = "Activity", colour = "Sector",
       title = "Trends in Orthopaedic activity by sector and procedure",
       subtitle = "Monthly elective inpatient admissions and outpatient appointments | National | 2017-22")

Chart text …

The most commonly undertaken orthopaedic procedures appear to be done on hands, knees and feet. The impacts of the COVID-19 pandemic appear to have been felt equally across different procedures; all seeing significant reductions and most not fully recovering to pre-pandemic levels. Within orthopaedic care, the market share taken up by the independent sector is relatively stable; similarly, the make-up of that IS market share is not dominated by any single procedure type - the types of procedures performed by the independent sector has remained stable in the post-pandemic era.

3.1.4.2 Independent sector share

# Orthopaedics 
national_data %>% 
  filter(speciality == "Orthopaedic") %>% 
  group_by(der_activity_month, type, procedure_desc_short) %>% 
  summarise(n_spells_IP = sum(n_spells_IP, na.rm = TRUE),
            n_spells_OP = sum(n_spells_OP, na.rm = TRUE)) %>% 
  pivot_longer(cols = c(n_spells_IP, n_spells_OP)) %>% 
  pivot_wider(id_cols = c(der_activity_month,  procedure_desc_short,name), 
              names_from = type,
              values_from = value) %>% 
  group_by(der_activity_month, procedure_desc_short, name) %>% 
  mutate(IS_prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`, na.rm = TRUE) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", TRUE ~ "Outpatient appointments")) %>% 
  filter(der_activity_month > "2018-01-01" & der_activity_month < "2022-11-01") %>% 
  drop_na(procedure_desc_short) %>% 
  
  ggplot(aes(x = der_activity_month, y = IS_prop, colour = name)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short#, scales = "free"
  ) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "bottom") +
  scale_color_SU() +
  labs(x = "", y = "Independent sector market share (%)", colour = "Activity type", 
       title = "Share of activity delivered by the independent sector: Orthopaedic",
       subtitle = "Monthly elective inpatient and outpatient activity | National | 2017-22")

Section text …

3.1.5 Opthalmic procedures

3.1.5.1 Volume

3.1.5.1.1 Fixed scale
national_data_procedure %>%  
  filter(speciality == "Ophthalmology") %>% 
  group_by(der_activity_month, type, speciality, procedure_desc_short) %>% 
  mutate(all_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  
  ggplot(aes(x = der_activity_month, y = all_activity, colour = type)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short#, scales = "free"
             ) +
  scale_color_SU() +
  scale_y_continuous(labels = comma) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = c(0.7,0.1)
        ) +
  labs(x = "", y = "Activity", colour = "Sector",
       title = "Trends in Ophthalmology activity by sector and procedure",
       subtitle = "Monthly elective inpatient admissions and outpatient appointments | National | 2017-22")

If we view the trends in ophthalmic elective procedures over the last 5 years by procedure type on a fixed scale, we see Vitreous Retinal procedures are much more common than any others. Such 200,000 of these procedures are undertaken monthly at the national level. Rates were halved at the peak of the pandemic and have return to near pre-pandemic levels in recent months.

3.1.5.1.2 Free scale
national_data_procedure %>%  
  filter(speciality == "Ophthalmology") %>% 
  group_by(der_activity_month, type, speciality, procedure_desc_short) %>% 
  mutate(all_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  
  ggplot(aes(x = der_activity_month, y = all_activity, colour = type)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short, scales = "free") +
  scale_color_SU() +
  scale_y_continuous(labels = comma) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = c(0.7,0.1)
        ) +
  labs(x = "", y = "Activity", colour = "Sector",
       title = "Trends in Ophthalmology activity by sector and procedure",
       subtitle = "Monthly elective inpatient admissions and outpatient appointments | National | 2017-22")

By viewing trends on variable scales, we see procedure-specific patterns more clearly. We note that Ocular Motility, Oculoplastics and Orbit and Lacrimal procedures have not returned to pre-pandmic levels and post-pandemic rates have plateaued. Rates in Cornea and Sclera procedures along with Glaucoma treatments have been trending upwards in NHS settings since early 2021. Is this a procedure type for which demand could be eased by increased provision in the independent sector?

3.1.5.1.3 Selected procedures
# Cataract and Vitreous Retinal procedures
national_data_procedure %>%  
  filter(speciality == "Ophthalmology", 
         procedure_desc_short %in% c("Cataract", 
                                     "Vitreous Retinal")) %>% 
  group_by(der_activity_month, type, speciality, procedure_desc_short) %>% 
  mutate(all_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  
  ggplot(aes(x = der_activity_month, y = all_activity, colour = type)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short, scales = "free") +
  scale_color_SU() +
  scale_y_continuous(labels = comma) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = "bottom"
        ) +
  labs(x = "", y = "Activity", colour = "Sector",
       title = "Trends in Ophthalmology activity by sector and procedure",
       subtitle = "Monthly elective inpatient admissions and outpatient appointments | National | 2017-22")

Focusing on trends in provision of Vitreous Retinal procedures and Cataract surgeries, our primary observations are that:

  • The provision of NHS-funded cataract procedures in the private sector has now overtaken that in NHS settings - data has been trending towards this throughout our data collection period but has overtaken only in recent months
  • The independent sector’s market share of vitreous retinal procedures has been gradually increasing and continues to do so since the pandemic - this is significant given the sizable market that vitreous retinal procedures represents.

3.1.5.2 Independent sector share

3.1.5.2.1 Fixed scale
# IS proportion by speciality and activity type (IP/OP)
# Ophthalmology
national_data %>% 
  filter(speciality == "Ophthalmology") %>% 
  group_by(der_activity_month, type, procedure_desc_short) %>% 
  summarise(n_spells_IP = sum(n_spells_IP, na.rm = TRUE),
            n_spells_OP = sum(n_spells_OP, na.rm = TRUE),
            #all_activity = sum(n_spells_IP, n_spells_OP, na.rm = TRUE)
            ) %>% 
  pivot_longer(cols = c(n_spells_IP, n_spells_OP)) %>% 
  pivot_wider(id_cols = c(der_activity_month,  procedure_desc_short,name), 
              names_from = type,
              values_from = value
              ) %>% 
  group_by(der_activity_month, procedure_desc_short, name) %>% 
  mutate(IS_prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`, na.rm = TRUE) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", TRUE ~ "Outpatient appointments")) %>% 
  filter(der_activity_month > "2018-01-01" & der_activity_month < "2022-11-01") %>% 
  drop_na(procedure_desc_short) %>% 
  filter(is.finite(IS_prop)) %>% 
  
  ggplot(aes(x = der_activity_month, y = IS_prop, colour = name)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short#, scales = "free"
             ) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = c(0.75,0.2)) +
  scale_color_SU() +
  labs(x = "", y = "Independent sector market share (%)", colour = "Activity type", 
       title = "Share of activity delivered by the independent sector: Ophthalmology",
       subtitle = "Monthly elective inpatient and outpatient activity | National | 2017-22")

3.1.5.2.2 Free scale
# IS proportion by speciality and activity type (IP/OP)
# Ophthalmology
national_data %>% 
  filter(speciality == "Ophthalmology") %>% 
  group_by(der_activity_month, type, procedure_desc_short) %>% 
  summarise(n_spells_IP = sum(n_spells_IP, na.rm = TRUE),
            n_spells_OP = sum(n_spells_OP, na.rm = TRUE),
            #all_activity = sum(n_spells_IP, n_spells_OP, na.rm = TRUE)
            ) %>% 
  pivot_longer(cols = c(n_spells_IP, n_spells_OP)) %>% 
  pivot_wider(id_cols = c(der_activity_month,  procedure_desc_short,name), 
              names_from = type,
              values_from = value
              ) %>% 
  group_by(der_activity_month, procedure_desc_short, name) %>% 
  mutate(IS_prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`, na.rm = TRUE) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", TRUE ~ "Outpatient appointments")) %>% 
  filter(der_activity_month > "2018-01-01" & der_activity_month < "2022-11-01") %>% 
  drop_na(procedure_desc_short) %>% 
  filter(is.finite(IS_prop)) %>% 
  
  ggplot(aes(x = der_activity_month, y = IS_prop, colour = name)) +
  geom_smooth(method = "loess", span = 0.2) +
  facet_wrap(~procedure_desc_short, scales = "free"
             ) +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold"),
        legend.position = c(0.75,0.2)) +
  scale_color_SU() +
  labs(x = "", y = "Independent sector market share (%)", colour = "Activity type", 
       title = "Share of activity delivered by the independent sector: Ophthalmology",
       subtitle = "Monthly elective inpatient and outpatient activity | National | 2017-22")

3.2.2 Ophthalmology

3.2.2.1 Age

national_data_ophthal %>% 
  wrangle_function(., age_range) %>% 
  filter(var_1 != "100+") %>% 
  graph_function(., "Ophthalmology") +
  facet_grid(~var_1, scales = "free")

3.2.2.2 Ethnicity

national_data_ophthal %>% 
  mutate(ethnic_group = case_when(ethnic_group %in% c("NULL", "99") ~ "Z", TRUE ~ ethnic_group)) %>% 
  mutate(ethnic_group = str_sub(ethnic_group, 1,1)) %>% 
  left_join(ethnicity_lookup, by = c("ethnic_group" = "Code")) %>% 
  wrangle_function(., ethnicity_broad) %>% 
  filter(var_1 != "Not stated_broad") %>% 
  graph_function(., "Ophthalmology") +
  facet_grid(~var_1, scales = "free")

3.2.2.3 Deprivation

national_data_ophthal %>% 
  wrangle_function(., imd_quintile) %>% 
  graph_function(., "Ophthalmology") +
  facet_grid(~var_1, scales = "free")

3.2.2.4 Wait time

national_data_ophthal %>% 
  wrangle_function(., duration_elective_wait_range) %>% 
  filter(var_1 != "500+") %>% 
  pivot_longer(cols = c(`Independent Sector`, NHS),
               names_to = "sector",
               values_to = "value"
               ) %>% 
  mutate(year = lubridate::year(der_activity_month)) %>% 
  group_by(year, var_1, name, sector) %>% 
  summarise(value = sum(value)) %>% 
  group_by(year, name, sector) %>% 
  mutate(prop = value/sum(value)*100) %>% 
  
  ggplot(aes(x = year, y = prop, fill = var_1)) +
  geom_col(position = "stack", colour = "grey", alpha = 0.9, width = 0.7) +
  facet_grid(name~sector) +
  scale_fill_SU() +
  theme(#legend.position = "none",
    strip.background = element_rect(fill = NA, colour = "grey"),
    strip.text = element_text(face = "bold"),
    axis.title.x = element_blank()
    ) +
  labs(y = "Proportion (%)",
       fill = "Wait duration (days)",
       title = "Change in wait time for treatment",
       subtitle = "Proportion of elective ophthalmology care contacts by wait time | National | 2018-22"
  )

We attempt to assess the impact of deprivation and ethnicity independently by using the following plots:

# Ethnicity and deprivation 
national_data_ortho %>%
  mutate(ethnic_group = case_when(ethnic_group %in% c("NULL", "99") ~ "Z", TRUE ~ ethnic_group)) %>% 
  mutate(ethnic_group = str_sub(ethnic_group, 1,1)) %>% 
  left_join(ethnicity_lookup, by = c("ethnic_group" = "Code")) %>% 
  
  group_by(der_activity_month, imd_quintile, ethnicity_broad, type) %>% 
  sum_spells_function(.) %>% 
  group_by(der_activity_month, type, imd_quintile, ethnicity_broad) %>% 
  mutate(total_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  pivot_longer(cols = c(-der_activity_month, -type, -ethnicity_broad, -imd_quintile)) %>% 
  pivot_wider(id_cols = c(der_activity_month, ethnicity_broad, imd_quintile, name), 
              names_from = type,
              values_from = value
              ) %>% 
  mutate(`Independent Sector` = case_when(is.na(`Independent Sector`) ~ 0, TRUE ~ `Independent Sector`)) %>% 
  group_by(der_activity_month, ethnicity_broad, imd_quintile, name) %>% 
  mutate(prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", 
                          str_detect(name, "OP") ~ "Outpatient appointments",
                          str_detect(name, "cost") ~ "Costs",
                          TRUE ~ "All activity")) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  filter(name != "All activity") %>% 
  ungroup() %>% 
  filter(name != "Costs") %>%
  filter(ethnicity_broad != "Not stated_broad") %>% 
  filter(is.finite(prop)) %>% 
  
  ggplot(aes(x = der_activity_month, y = prop, colour = name)) +
  geom_smooth(method = "loess", span = 0.3, size = 0.75) +
  facet_grid(str_wrap(ethnicity_broad,13)~imd_quintile) +
  scale_color_SU() +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold", size = 8), 
        axis.text.x = element_text(angle = 90),
        legend.position = "bottom",
        axis.text = element_text(size = 7),
        axis.title.x = element_blank()
        ) +
  labs(y = "Independent sector proportion (%)",
       colour = "",
       title = "Independent sector proportion of activity by deprivation quintile and ethnic group",
       subtitle = "Orthopaedic elective procedures | National | 2018-22")

national_data_ophthal %>%
  mutate(ethnic_group = case_when(ethnic_group %in% c("NULL", "99") ~ "Z", TRUE ~ ethnic_group)) %>% 
  mutate(ethnic_group = str_sub(ethnic_group, 1,1)) %>% 
  left_join(ethnicity_lookup, by = c("ethnic_group" = "Code")) %>% 
  
  group_by(der_activity_month, imd_quintile, ethnicity_broad, type) %>% 
  sum_spells_function(.) %>% 
  group_by(der_activity_month, type, imd_quintile, ethnicity_broad) %>% 
  mutate(total_activity = sum(n_spells_IP, n_spells_OP)) %>% 
  pivot_longer(cols = c(-der_activity_month, -type, -ethnicity_broad, -imd_quintile)) %>% 
  pivot_wider(id_cols = c(der_activity_month, ethnicity_broad, imd_quintile, name), 
              names_from = type,
              values_from = value
              ) %>% 
  mutate(`Independent Sector` = case_when(is.na(`Independent Sector`) ~ 0, TRUE ~ `Independent Sector`)) %>% 
  group_by(der_activity_month, ethnicity_broad, imd_quintile, name) %>% 
  mutate(prop = `Independent Sector`/ sum(`Independent Sector`, `NHS`) * 100) %>% 
  mutate(name = case_when(str_detect(name, "IP") ~ "Inpatient admissions", 
                          str_detect(name, "OP") ~ "Outpatient appointments",
                          str_detect(name, "cost") ~ "Costs",
                          TRUE ~ "All activity")) %>% 
  filter(der_activity_month > "2018-01-01" &
           der_activity_month < "2022-11-01") %>%
  filter(name != "All activity") %>% 
  ungroup() %>% 
  filter(name != "Costs") %>%
  filter(ethnicity_broad != "Not stated_broad") %>% 
  
  ggplot(aes(x = der_activity_month, y = prop, colour = name)) +
  geom_smooth(method = "loess", span = 0.3, size = 0.75) +
  facet_grid(str_wrap(ethnicity_broad,13)~imd_quintile) +
  scale_color_SU() +
  theme(strip.background = element_rect(fill = NA, colour = "grey"),
        strip.text = element_text(face = "bold", size = 8), 
        axis.text.x = element_text(angle = 90),
        legend.position = "bottom",
        axis.text = element_text(size = 7),
        axis.title.x = element_blank()
        ) +
  labs(y = "Independent sector proportion (%)",
       colour = "",
       title = "Independent sector proportion of activity by deprivation quintile and ethnic group",
       subtitle = "Ophthalmology elective procedures | National | 2018-22")


Volume section desc

3.3.1.2 Independent sector share

3.3.1.2.1 Orthopaedic
stp_data_ortho %>% 
  wrangle_function(., nhser20nm) %>% 
  filter(!is.nan(prop)) %>% 
  graph_function(., "Orthopaedic") +
  facet_grid(~str_wrap(var_1,15))

Graph desc…

3.3.1.2.2 Ophthalmology
stp_data_ophthal %>% 
  wrangle_function(., nhser20nm) %>% 
  filter(!is.nan(prop)) %>% 
  graph_function(., "Ophthalmology") +
  facet_grid(~str_wrap(var_1,15))

Graph desc…

Independent sector share section desc …

3.3.2 STP/ICB

3.3.2.1 Speciality

3.3.2.1.1 Orthopaedic
ICB_graph_function(stp_data_ortho, "Orthopaedic")

Graph desc…

3.3.2.1.2 Ophthalmology
ICB_graph_function(stp_data_ophthal, "Ophthalmology")

Graph desc…

STP/ICB section desc …

3.3.2.2 Procedure

3.3.2.2.1 Cataract
ICB_graph_function(stp_data_ophthal %>% 
                     filter(procedure_desc_short == "Cataract"), 
                   "Ophthalmology - Cataract")

Graph desc…

3.3.2.2.2 Vitreous Retinal
ICB_graph_function(stp_data_ophthal %>% 
                     filter(procedure_desc_short == "Vitreous Retinal"), 
                   "Ophthalmology - Vitreous Retinal")

Graph desc…

3.3.2.2.3 Glaucoma
ICB_graph_function(stp_data_ophthal %>% 
                     filter(procedure_desc_short == "Glaucoma"), 
                   "Ophthalmology - Glaucoma")

Graph desc…

Section desc

3.3.2.3 Demographic - deprivation

3.3.2.3.1 Quintile 1
ICB_graph_function(stp_data_ophthal %>% 
                     filter(imd_quintile == 1), 
                   "Ophthalmology - IMD quintile 1")

Graph desc…

3.3.2.3.2 2
ICB_graph_function(stp_data_ophthal %>% 
                     filter(imd_quintile == 2), 
                   "Ophthalmology - IMD quintile 2")

Graph desc…

3.3.2.3.3 3
ICB_graph_function(stp_data_ophthal %>% 
                     filter(imd_quintile == 3), 
                   "Ophthalmology - IMD quintile 3")

Graph desc…

3.3.2.3.4 4
ICB_graph_function(stp_data_ophthal %>% 
                     filter(imd_quintile == 4), 
                   "Ophthalmology - IMD quintile 4")

Graph desc…

3.3.2.3.5 Quintile 5
ICB_graph_function(stp_data_ophthal %>% 
                     filter(imd_quintile == 5), 
                   "Ophthalmology - IMD quintile 5")

Graph desc…


4 Further discussion/Questions